
package jogs.net;

import java.io.*; 
import java.net.*; 

public class TCPClientHandler extends Thread 
{  
  private Socket socket;
  private int id; 
  private TCPGameServer server;
  
  private BufferedReader input;
  private PrintStream output; 
  
  public TCPClientHandler(Socket _socket, int _id, TCPGameServer _server)
  {
    socket = _socket; 
    id = _id; 
    server = _server;
  }
  
  public void run()
  {
    try 
    {     
      input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      output = new PrintStream(socket.getOutputStream()); 
      
      String line = "";
      line = input.readLine();
      
      while (line != null && !line.equals(Constants.CLIENT_EXIT))
      {
        server.handleMessage(id, line);       
        line = input.readLine(); 
      }
    }
    catch(Exception e)
    {
      e.printStackTrace(); 
    }
  }
  
  public void send(String msg)
  {
    output.println(msg);
  }
  
  public boolean isDisconnected()
  {
    return false; 
  }
}
